package com.kehutong.common.Authutil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;


/**
 * TODO 拼接字符串
 *
 * @author zhouweipeng
 * @version 1.0
 * @date 2021/7/19 10:18
 */
public class SignUtils {

    public static String linkString(Map<String,Object> params) {
        List<String> keys = new ArrayList<String>(params.keySet());
        Collections.sort(keys);
        String prestr = "";
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = params.get(key).toString();
            if (value == null || value.equals("")) {
                continue;
            }
            if (i == keys.size() - 1) {// 拼接时，不包括最后一个&字符
                prestr = prestr + key + "=" + value;
            } else {
                prestr = prestr + key + "=" + value + "&";
            }
        }
        if(prestr.endsWith("&")) {
            prestr = prestr.substring(0 , prestr.length() - 1);
        }
        return prestr;
    }



}
